package Easy对称二叉树;

import org.testng.annotations.Test;

public class Solution {
    public boolean isSymmetric(TreeNode root) {
        boolean[] bool= {true};
        if (root == null)
            return true;
        TreeNode a = root.left;
        TreeNode b = root.right;
        bool = isEmpty(a,b,bool);
        return bool[0];
    }
    public boolean[] isEmpty(TreeNode a, TreeNode b,boolean[] bool){
        if (a==null && b==null)
            return bool;
        else if (a!=null && b!=null && a.val == b.val){
            isEmpty(a.left,b.right,bool);
            isEmpty(a.right,b.left,bool);
        }
        else {
            bool[0] = false;
            return bool;
        }
        return bool;
    }
    @Test
    public void test(){
        TreeNode tree = new TreeNode(1,new TreeNode(2,new TreeNode(3),new TreeNode(4)),new TreeNode(2,new TreeNode(4),new TreeNode(3)));
        System.out.println(isSymmetric(tree));
    }
}
